{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现基于keras搭建LSTM神经网络，并基于训练集对模型进行训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from keras.layers import LSTM, Dense\n",
    "from keras.models import Sequential\n",
    "import keras\n",
    "import pickle\n",
    "\n",
    "SEQLEN = 14\n",
    "dim_in = 108\n",
    "dim_out = 96\n",
    "pred_len = 30\n",
    "\n",
    "with open('data/X_train.pkl', 'rb') as f:\n",
    "    X_train = pickle.load(f)\n",
    "\n",
    "with open('data/Y_train.pkl', 'rb') as f:\n",
    "    Y_train = pickle.load(f)\n",
    "    \n",
    "model = Sequential()\n",
    "init = keras.initializers.glorot_uniform(seed=90)\n",
    "model.add(LSTM(128, input_shape=(SEQLEN, dim_in), activation='relu', kernel_initializer=init, recurrent_dropout=0.01))\n",
    "model.add(Dense(dim_out, activation='linear'))\n",
    "model.compile(loss='mse', optimizer='rmsprop')\n",
    "history = model.fit(X_train, Y_train, epochs=2000, batch_size=7, validation_split=0)\n",
    "\n",
    "with open('data/model.pkl', 'wb') as f:\n",
    "    pickle.dump(model, f)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
